<template>
  <div class="app-container">
    <div style="width: 600px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="姓名" prop="name">
          <el-input size="small" v-model="form.name" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input size="small" v-model="form.phone" />
        </el-form-item>
        <el-form-item label="登录账号" prop="account">
          <el-input size="small" v-model="form.account" />
        </el-form-item>
        <el-form-item label="登录密码" prop="password">
          <el-input size="small" v-model="form.password" />
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="onSubmit('form')">新建</el-button>
          <el-button size="small" @click="onCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: '',
        phone: '',
        account: '',
        password: '',
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
        ],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
        ],
        account: [
          { required: true, message: '请输入登录账号', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
        ],
      }
    }
  },
  methods: {
    onSubmit(formName) {
      // this.$message('submit!')
      this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>
